/**
 * Created by Administrator on 14-10-24.
 */
/* 保存状态 */
function saveResult(saveState, desc, callback) {
    var descTxt = saveState ? "保存成功" : "保存失败";
    descTxt = desc ? desc : descTxt;
    var html1 = $('<div class="submit-success">' +
    '<img src="../images/sub-status-1.png" width="25%" alt=""/>' +
    '<p>' + saveState + '</p><p>' + desc + '</p>' +
    '</div>');
    var html2 = $('<div class="submit-success">' +
    '<img src="../images/sub-status-2.png" width="25%" alt=""/>' +
    '<p>' + descTxt + '</p>' +
    '</div>');
    if (saveState) {
        $('body').append(html1);
        var width = $(html1).outerWidth();
        $(html1).css("left", ($(window).innerWidth() - width) / 2);
        setTimeout(function () {
            html1.fadeOut(800, function () {
                $(this).remove();
                if (callback) {
                    callback();
                }
            });
        }, 1000);
    } else {
        $('body').append(html2);
        var width = $(html2).outerWidth();
        $(html2).css("left", ($(window).innerWidth() - width) / 2);
        setTimeout(function () {
            html2.fadeOut(800, function () {
                $(this).remove();
                if (callback) {
                    callback();
                }
            });
        }, 1000);
    }
}


$(function () {
    $(".menu-toggle-new").click(function () {
        if ($(".menu-pop-new").css("display") == "none") {
            $(".menu-pop-new").show();
            $("#zhezhao").removeClass("none");
        } else {
            $(".menu-pop-new").hide();
            $("#zhezhao").addClass("none");
        }

    });
    $("#zhezhao").click(function () {
        $("#zhezhao").addClass("none");
        $(".menu-pop-new").hide();
    });

    $(".menu-pop-new ul li a").on("click", function () {
        if ($(this).is($(".menu-pop-new ul li a").last()) || $(this).is($(".menu-pop-new ul li a").first())) {
            $(this).css({borderRadius: "3px"});
        }
        $(this).css({backgroundColor: "#4d4d4d"});
        window.setTimeout(function () {
            $(".menu-pop-new ul li a").css({backgroundColor: "transparent"});
        }, 200)

    });

});

/**
 * author:王立雍
 */
function alertMessage(msg) {
    $(".tooltips").remove();
    var $hint = $('<div class="tooltips" style="width:90%;box-sizing:border-box;padding:5px 10px 1px;border-radius:5px;background-color:rgba(0,0,0,.5);position:fixed;bottom:-20px;left:5%;color:#fff;z-index:10000;text-align:center"><table style="display:inline-block;"><tr><td><span style="display:inline-block;padding-left:10px;font-size:0.875em;line-height:1.3em;vertical-align:middle;text-align:left;padding-bottom:1px;">' + msg + '</span></td></tr></table></div>');
    $('body').append($hint);
    $hint.animate({bottom: 100}, 200);
    window.setTimeout(function () {
        $hint.remove();
    }, 2000);
};


/*购房币提醒*/
function getMoneyPopup(getNum, usableNum, callback) {
    var $html = $('<div style="width:144px;padding:15px 10px 15px 15px;position:fixed;bottom:-76px;left:50%;margin-left:-82px;background-color:rgba(0,0,0,.8);border-radius:5px;z-index:10000;">' +
    '<div style="display:inline-block;width:24px;height:19px;padding-right:5px;background:url(../images/bg-icons-01.png) no-repeat -29px -156px;background-size:120px 180px;vertical-align:middle;"></div>' +
    '<div style="display:inline-block;widht:auto;padding-right:5px;vertical-align:middle;">' +
    '<p style="font-size:0.75em;color:#e8c27e;">获得：<span style="position:relative;top:-1px;font-size:1.25em;color:#ffb426;font-weight:bold;">+</span><span class="getMoney" style="position:relative;top:1px;font-size:1.25em;color:#c1881f;font-weight:bold;">0</span></p>' +
    '<p style="font-size:0.75em;color:#e8c27e;">可用：<span style="position:relative;top:1px;font-size:1.25em;color:#c1881f;font-weight:bold;">' + usableNum + '</span></p>' +
    '</div></div>');
    $("body").append($html);
    $html.stop().animate({bottom: 95}, {
        duration: 300, easing: 'easeOutBack', complete: function () {
            addNum($(this).find(".getMoney"), getNum);
        }
    });
    window.setTimeout(function () {
        $html.stop().animate({opacity: 0}, 800, function () {
            $(this).remove();
            callback();
        });
    }, 1500);
}
/*数字动态增加*/
function addNum(obj, getNum) {
    var initialNum = parseInt(obj.html());
    var addNum = parseInt(getNum / 5);
    if (addNum > 1) {
        var numAn = setInterval(function () {
            initialNum += addNum;
            if (initialNum >= getNum) {
                initialNum = getNum;
                obj.html(initialNum);
                clearInterval(numAn);
            }
            obj.html(initialNum);
        }, 100);
    } else {
        obj.html(getNum);
    }
}

/*图片宽高设置*/
window.onload = function () {
    var $scaleImg = $("img[data-set=scale]");
    var $sizeImg = $("img[data-set=fixedSize]");
    var screenWid = $(window).width();
    $scaleImg.each(function () {
        $(this).css('width', screenWid + 'px');
        var imgHig = $(this).height();
        var $span = $("<span style='display:block;position:relative;overflow:hidden;background-color:#000;'><span>");
        var dataScale = $(this).attr('scale-width') / $(this).attr('scale-height');
        var imgScale = screenWid / imgHig;
        $span.css({width: screenWid + 'px', height: screenWid / dataScale + 'px'}).find('span').remove();
        $(this).parent().append($span);
        $(this).appendTo($span);
        if (imgScale != 0) {
            $(this).css({top: '50%', marginTop: -imgHig / 2 + 'px'});
        } else {
            $(this).css('height', screenWid / dataScale + 'px');
        }
    });
    $sizeImg.each(function () {
        var showWid = parseInt($(this).attr("size-width"));
        var showHig = parseInt($(this).attr("size-height"));
        $(this).css('width', showWid + 'px');
        var imgHig = $(this).height();
        var $span = $("<span style='display:block;position:relative;float:left;overflow:hidden;padding-right:10px;'><span>");
        $span.css({width: showWid + 'px', height: showHig + 'px'}).find('span').remove();
        $(this).before($span);
        $(this).appendTo($span);
        if (imgHig == 0) {
            $(this).css('height', showHig);
        } else {
            $(this).css({top: '50%', marginTop: -imgHig / 2 + 'px'});

        }
    });
}